import axios from 'axios'

let env = process.env.NODE_ENV;
let baseURL = '';
if (env === 'development') {
    baseURL = 'http://jun.huruqing.cn:3000/admin';
} else {
    baseURL = 'http://jun.huruqing.cn:3000/admin';
}

const service = axios.create({
    // 配置基本的路径
    baseURL,
    timeout: 5000 // 请求超时时间(因为需要调试后台,所以设置得比较大)
})
// request拦截器
service.interceptors.request.use(
    config => {
        // 请求头添加token
        config.headers['token'] = 'gg12j3h4ghj2g134kj1g234gh12jh34k12h34g12kjh34kh1g';
        return config
    },
    error => {
        Promise.reject(error)
    }
)


service.interceptors.response.use(res => {
    if (res.data.code == 666) {
        return res.data
    } else {
        return Promise.reject(res.data.msg);
    }
},
    error => {
        return Promise.reject(error)
    });


console.log('service', service);
export default service;